﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics;

namespace Demo6
{
    public class SpacePhysicsHelpers
    {
        public static Body CreateRectangleBody(float width, float height, float mass)
        {
            Body body = new Body();
            body.Mass = mass;
            body.MomentOfInertia = mass * (width * width + height * height) / 12;
            return body;
        }

        //http://www.cameronalbert.com/post.aspx?id=1b69e6be-8a2d-49be-8d63-716e54dd1f61
        public static void DrawVertices(Canvas debugCanvas, PhysicsSimulator physicsSimulator)
        {
            debugCanvas.Children.Clear();
            int verticeCount = 0;
            for (int i = 0; i < physicsSimulator.GeomList.Count; i++)
            {
                verticeCount = physicsSimulator.GeomList[i].LocalVertices.Count;
                for (int j = 0; j < verticeCount; j++)
                {
                    Line line = new Line();
                    line.Fill = new SolidColorBrush(Colors.Transparent);
                    line.Stroke = new SolidColorBrush(Colors.Magenta);
                    line.StrokeThickness = 1;
                    if (j < verticeCount - 1)
                    {
                        line.X1 = physicsSimulator.GeomList[i].WorldVertices[j].X;
                        line.Y1 = physicsSimulator.GeomList[i].WorldVertices[j].Y;
                        line.X2 = physicsSimulator.GeomList[i].WorldVertices[j + 1].X;
                        line.Y2 = physicsSimulator.GeomList[i].WorldVertices[j + 1].Y;
                    }
                    else
                    {
                        line.X1 = physicsSimulator.GeomList[i].WorldVertices[j].X;
                        line.Y1 = physicsSimulator.GeomList[i].WorldVertices[j].Y;
                        line.X2 = physicsSimulator.GeomList[i].WorldVertices[0].X;
                        line.Y2 = physicsSimulator.GeomList[i].WorldVertices[0].Y;
                    }
                    debugCanvas.Children.Add(line);
                }
            }
        }

    }
}
